// 状态栏
var snMenu = document.getElementsByClassName("sn-menus");
var fnMenu = document.getElementsByClassName("fn-menus");
var img = document.getElementsByClassName("sn-menu-imgs");
for (let i = 0; i < snMenu.length; i++) {
    snMenu[i].onmousemove = function() {
        fnMenu[i].style.display = "block";
        snMenu[i].style.backgroundColor = "white";
        img[i].style.transform = "rotate(180deg)";
    }
    snMenu[i].onmouseout = function() {
        fnMenu[i].style.display = "none";
        snMenu[i].style.backgroundColor = "#f2f2f2";
        img[i].style.transform = "rotate(0deg)";
    }
}

// 调出json中储存的图片路径
ajax("get", "../js/tmall_HomePage.json", true, function(res) {
    var oRes = JSON.parse(res.responseText);
    console.log(oRes);
    var imgs = document.getElementsByClassName("swiper-wrapper");
    for (var i = 0; i < oRes.url.length; i++) {
        console.log(oRes.url[i]);
        imgs[0].innerHTML += `<div class="swiper-slide"><img src="${oRes.url[i]}"></div>`;
    }
    document.getElementsByClassName("right")[0].innerHTML = `<img src="${oRes.img}">`;
    document.getElementsByClassName("banner-img")[0].innerHTML = `<img src="${oRes.img2}">`;
});

// 轮播
var swiper = new Swiper('.swiper-container', {
    autoplay: true,
    observer: true, //修改swiper自己或子元素时，自动初始化swiper
    observeParents: true, //修改swiper的父元素时，自动初始化swiper
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
        renderBullet: function(index, className) {
            return '<span class="' + className + '">' + (index + 1) + '</span>';
        },
    },
});